// search 数据仓库

import { reqSearchInfo } from "@/api"

// 存储数据
const state = {
    searchInfo: {},
}

// 修改数据
const mutations = {
    GETSEARCHINFO(state, searchInfo) {
        state.searchInfo = searchInfo
    }
}

// 书写业务逻辑 处理异步
const actions = {
    async getSearchInfo({ commit }, params) {
        let result = await reqSearchInfo(params)
        if (result.code == 200) {
            commit('GETSEARCHINFO', result.data)
        }
    }
}

// 计算属性 简化数据
const getters = {
    // 当前仓库的 state  没有数据时返回[] 而不是 undefined
    goodsList(state) {
        return state.searchInfo.goodsList || []
    },
    trademarkList(state) {
        return state.searchInfo.trademarkList || []
    },
    attrsList(state) {
        return state.searchInfo.attrsList || []
    },
}

export default {
    state,
    mutations,
    actions,
    getters
}